rem ========================================================================================================================
rem   SPPackager.SPDeploy - Perform the instalation, upgrade and retraction of Ms Sharepoint Applications fast, easy and efficient
rem   PostBuild version 1.0 - Jan, 30th of 2013
rem   Frederico Souza Lima (fredericosl@hotmail.com)
rem   Michael Moraes Capela (michaelcapela@hotmail.com)
rem   Copyright (c) 2012-2013
rem ========================================================================================================================

rem "Packager Solution Path"

set SPPackagerSolutionPath=C:\PROJECTS\SPPackager\SPPackager
set SPBusinessSolutionPath=C:\PROJECTS\SPBusiness\SPBusiness
set SPPackagerDeployProjectPath=%SPPackagerSolutionPath%\SPPackager.SPDeploy


rem "Local Solution Path"

set LocalSolutionPath=C:\PROJECTS\SLB.COE.BPI.ServiceOrder\TFS
set LocalDeployProjectPath=%LocalSolutionPath%\SLB.COE.BPI.ServiceOrder.Deploy

IF not exist "%LocalDeployProjectPath%\FarmSolutions" ( mkdir "%LocalDeployProjectPath%\FarmSolutions")
IF not exist "%LocalDeployProjectPath%\UserSolutions" ( mkdir "%LocalDeployProjectPath%\UserSolutions")

attrib -r "%LocalDeployProjectPath%\FarmSolutions\*.*"
attrib -r "%LocalDeployProjectPath%\UserSolutions\*.*"
attrib -r "%LocalDeployProjectPath%\*.bat"
attrib -r "%LocalDeployProjectPath%\*.ps1"
attrib -r "%LocalDeployProjectPath%\*.xml"

rem "MSOCAF Root Path"

set LocalDeployMSOCAFRootPath=%LocalDeployProjectPath%\MSOCAF\Root

IF not exist "%LocalDeployMSOCAFRootPath%\Installation scripts" ( mkdir "%LocalDeployMSOCAFRootPath%\Installation scripts") 
IF not exist "%LocalDeployMSOCAFRootPath%\Release documents" ( mkdir "%LocalDeployMSOCAFRootPath%\Release documents") 
IF not exist "%LocalDeployMSOCAFRootPath%\Solutions artifacts" ( mkdir "%LocalDeployMSOCAFRootPath%\Solutions artifacts") 
IF not exist "%LocalDeployMSOCAFRootPath%\Source code" ( mkdir "%LocalDeployMSOCAFRootPath%\Source code") 
IF not exist "%LocalDeployMSOCAFRootPath%\Test documents" ( mkdir "%LocalDeployMSOCAFRootPath%\Test documents") 

rem "User Solutions"

set LocalProject=SLB.COE.BPI.ServiceOrder.Portal
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployProjectPath%\UserSolutions\%LocalProject%.wsp" /Y)
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.wsp" /Y)
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.pdb" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.pdb" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.pdb" /Y)	
set LocalProject=

set LocalProject=SLB.COE.BPI.ServiceOrder.WebParts
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployProjectPath%\UserSolutions\%LocalProject%.wsp" /Y)
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.wsp" /Y)
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.pdb" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.pdb" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.pdb" /Y)	
set LocalProject=

rem "Business Solution - Different Path"

set LocalProject=SPBusiness
IF exist "%SPBusinessSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%SPBusinessSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployProjectPath%\FarmSolutions\%LocalProject%.wsp" /Y)
IF exist "%SPBusinessSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%SPBusinessSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.wsp" /Y)
IF exist "%SPBusinessSolutionPath%\%LocalProject%\bin\%2\*.pdb" (copy "%SPBusinessSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.pdb" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.pdb" /Y)	
set LocalProject=

rem "Farm Solutions"

set LocalProject=SLB.COE.BPI.ServiceOrder.Portal.Farm
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployProjectPath%\FarmSolutions\%LocalProject%.wsp" /Y)
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.wsp" /Y)
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.pdb" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.pdb" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.pdb" /Y)
set LocalProject=

set LocalProject=SLB.COE.BPI.ServiceOrder.WebParts.Farm
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployProjectPath%\FarmSolutions\%LocalProject%.wsp" /Y)
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.wsp" /Y)
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.pdb" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.pdb" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.pdb" /Y)
set LocalProject=

set LocalProject=SLB.COE.BPI.ServiceOrder.Proxy
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployProjectPath%\FarmSolutions\%LocalProject%.wsp" /Y)
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.wsp" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.wsp" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.wsp" /Y)
IF exist "%LocalSolutionPath%\%LocalProject%\bin\%2\*.pdb" (copy "%LocalSolutionPath%\%LocalProject%\bin\%2\%LocalProject%.pdb" "%LocalDeployMSOCAFRootPath%\Solutions artifacts\%LocalProject%.pdb" /Y)
set LocalProject=

attrib -r "%LocalDeployProjectPath%\FarmSolutions\*.*"
attrib -r "%LocalDeployProjectPath%\UserSolutions\*.*"
attrib -r "%LocalDeployMSOCAFRootPath%\Solutions artifacts\*.*"

IF not exist "%1FarmSolutions" ( mkdir "%1FarmSolutions")
copy "%LocalDeployProjectPath%\FarmSolutions" "%1FarmSolutions"  /y

IF not exist "%1UserSolutions" ( mkdir "%1UserSolutions")
copy "%LocalDeployProjectPath%\UserSolutions" "%1UserSolutions"  /y

copy "%SPPackagerDeployProjectPath%\*.ps1" "%LocalDeployProjectPath%\" /Y

copy "%SPPackagerDeployProjectPath%\Data - Deploy.bat" "%LocalDeployProjectPath%\Data - Deploy.bat" /Y
copy "%SPPackagerDeployProjectPath%\Navigation - Deploy.bat" "%LocalDeployProjectPath%\Navigation - Deploy.bat" /Y

copy "%SPPackagerDeployProjectPath%\ClearInstall - Deploy.bat" "%LocalDeployProjectPath%\ClearInstall - Deploy.bat" /Y
copy "%SPPackagerDeployProjectPath%\ReDeploy - Deploy.bat" "%LocalDeployProjectPath%\ReDeploy - Deploy.bat" /Y
copy "%SPPackagerDeployProjectPath%\Redeploy - Install.bat" "%LocalDeployProjectPath%\Redeploy - Install.bat" /Y
copy "%SPPackagerDeployProjectPath%\Redeploy - RepairFeatures.bat" "%LocalDeployProjectPath%\Redeploy - RepairFeatures.bat" /Y
copy "%SPPackagerDeployProjectPath%\Redeploy - UnInstall.bat" "%LocalDeployProjectPath%\Redeploy - UnInstall.bat" /Y

copy "%SPPackagerDeployProjectPath%\DataSchemaDeploy.xml" "%LocalDeployProjectPath%\DataSchemaDeploy.xml" /Y
copy "%SPPackagerDeployProjectPath%\NavigationSchemaDeploy.xml" "%LocalDeployProjectPath%\NavigationSchemaDeploy.xml" /Y
copy "%SPPackagerDeployProjectPath%\HostedApplicationsSchema.xml" "%LocalDeployProjectPath%\HostedApplicationsSchema.xml" /Y
copy "%SPPackagerDeployProjectPath%\SchemaDeploy.xml" "%LocalDeployProjectPath%\SchemaDeploy.xml" /Y

attrib -r "%LocalDeployProjectPath%\*.bat"
attrib -r "%LocalDeployProjectPath%\*.ps1"
attrib -r "%LocalDeployProjectPath%\*.xml"
attrib -r "%LocalDeployProjectPath%\*.txt"
attrib -r "%LocalDeployProjectPath%\*.docx"

copy "%LocalDeployProjectPath%\*.bat" "%1\"  /y
copy "%LocalDeployProjectPath%\*.ps1" "%1\"  /y
copy "%LocalDeployProjectPath%\*.xml" "%1\"  /y
copy "%LocalDeployProjectPath%\*.txt" "%1\"  /y
copy "%LocalDeployProjectPath%\*.docx" "%1\"  /y

copy "%LocalDeployProjectPath%\*.bat" "%LocalDeployMSOCAFRootPath%\Installation scripts\"  /y
copy "%LocalDeployProjectPath%\*.ps1" "%LocalDeployMSOCAFRootPath%\Installation scripts\"  /y
copy "%LocalDeployProjectPath%\*.xml" "%LocalDeployMSOCAFRootPath%\Installation scripts\"  /y
copy "%LocalDeployProjectPath%\*.docx" "%LocalDeployMSOCAFRootPath%\Release documents\"  /y

del "%1\*.dll"  /F /Q
del "%1\*.pdb"  /f /Q

set SPPackagerSolutionPath=
set SPBusinessSolutionPath=
set LocalSolutionPath=
set LocalDeployProjectPath=
set LocalDeployMSOCAFRootPath=